<?php
class WE_Validator_LoginPasswordOk extends Zend_Validate_Abstract
{
    const INVALIDE = 'identifiantsInvalides';
    
    protected $_authAdapter;

    protected $_messageTemplates = array(
        self::INVALIDE => '用户名与密码不符',
    );

    public function isValid($value, $context = null)
    {
        if (empty($context['password']) OR empty($context['username'])) {
            $this->_error(self::INVALIDE);
            return false;
        } else {
        	
            $auth = Zend_Auth::getInstance();
            $user = new Model_User();
            $this->_authAdapter = $user->getAuthAdapter($context['username'], $context['password']);
            $result = $auth->authenticate($this->_authAdapter);
            
            if ($result->isValid()) {
                return true;
            } else {
                $this->_error(self::INVALIDE);
                return false;
            }
            
        	return true;
        }
    }
    
    public function getAuthAdapter()
    {
        return $this->_authAdapter;
    }
}